/**
 * 
 */
package com.qachecklist.domain;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * Item is an element within the checklist. For example,
 * "popup X opens when button Y is clicked on page Z"
 * 
 * @author hirokiterashima
 */
@Entity
@Table(name="items")
public class Item extends PersistableDomain {
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Long id = null;
	
	@Column(name="name")
    private String name;  // short-hand name to refer to this item
	
	@ManyToOne(cascade={CascadeType.ALL})
	private ItemDescription itemDescription;  // description of this item
	
	@ManyToOne(cascade={CascadeType.ALL})
	private Environment environment;
	
	public Long getId() {
		return id;
	}

	@SuppressWarnings("unused")
	private void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public ItemDescription getItemDescription() {
		return itemDescription;
	}

	public void setItemDescription(ItemDescription itemDescription) {
		this.itemDescription = itemDescription;
	}

	public Environment getEnvironment() {
		return environment;
	}

	public void setEnvironment(Environment environment) {
		this.environment = environment;
	}

	protected Class<Item> getObjectClass() {
		return Item.class;
	}
	
	@Override
	public String toXMLString() {
		return 
			"<item><id>"+ this.getId() +"</id>"
			+ this.getEnvironment().toXMLString() 
			+ this.getItemDescription().toXMLString()
			+ "</item>";
	}
}
